home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / fminit2.0 / fix-html.pl < prev    next >
Encoding:
Perl Script  |  1992-11-17  |  1021 b   |  53 lines

  1. #!/usr/local/bin/perl
  2. #$Id: fix-html.pl,v 1.2 92/11/17 21:58:44 connolly Exp $
  3. #
  4. # USE
  5. #   fix-html.pl <W3-file.html >W3-file.sgml
  6. #
  7. # SEE ALSO
  8. #   the html.dtd.
  9. #
  10.  
  11. @html = <>;            # read whole file
  12. $_ = join('', @html);
  13.  
  14. while(/</){
  15.     &out($`);
  16.     $_ = $';
  17.     if(s/^A\s+//i){
  18.     &fix_anchor;
  19.     }elsif(s/^NEXTID\s+(\d+)\s*>//i){
  20.     # http://info.cern.ch/hypertext/WWW/MarkUp/HTML2.html
  21.     # specifies that the attribute is called ID
  22.     &out("<NEXTID ID=$1>");
  23.     }else{
  24.     &out('<');
  25.     }
  26. }
  27.  
  28. &out($_);
  29.  
  30. sub out{
  31.     print $_[0];
  32. }
  33.  
  34. sub fix_anchor{
  35.     local($name, $href, $type);
  36.  
  37.     # What exactly is the syntax of an SGML attribute value?
  38.     while(s/^(\w+)\s*=\s*((\"[^\"]*\")|([^\s>]+))\s*//){
  39.     local($v) = ($3 || $4);
  40.     local($a) = $1;
  41.     $href = $v if $a =~ /^href$/i;
  42.     $name = $v if $a =~ /^name$/i;
  43.     $type = $v if $a =~ /^type$/i;
  44.     }
  45.     s/[^>]*>//;
  46.  
  47.     &out("<A");
  48.     &out(" NAME=\"$name\"") if $name ne '';
  49.     &out(" TYPE=\"$type\"") if $type ne '';
  50.     &out(" HREF=\"$href\"") if $href ne '';
  51.     &out(">");
  52. }
  53.